#!python

# vPresent is an immersive presentation creation and display application.
# Copyright (C) 2007 by Infiscape Corporation
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

import os.path

import SCons
import SConsAddons.Util as sca_util


Import('*')
env = common_env.Copy()

def runPyuic(target = None, source = None, env = None):
   ui_file = str(source[0])
   py_file = str(target[0])
   pyuic_build_str = 'pyuic4 -x -i3 %s -o %s' % (ui_file, py_file)
   status = env.Execute(pyuic_build_str)

   if status == 0:
      stripCreationInfo(py_file)
      addLicense(py_file)

   return status

def registerPyuicBuilder(env):
   pyuic_builder = Builder(action = Action(runPyuic), src_suffix = '.ui',
                           suffix = '.py')
   env.Append(BUILDERS = {'Pyuic' : pyuic_builder})

registerPyuicBuilder(env)

ui_src_files = []
for path, dirs, files in sca_util.WalkBuildFromSource('.', env):
   ui_src_files += [os.path.join(path, f) for f in files if f.endswith('.ui')]

for f in ui_src_files:
   env.Pyuic(f)
